<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //使用function*来申明一个generator状态机对象
        function* generator() {

            // 使用关键字yield来定义每一次的状态
            yield console.log(1);
            yield console.log(2);
            yield console.log(3);
            yield console.log(4);
            yield console.log(5);
        }


        //调用generator函数，返回一个iterator的对象
        const result = generator()
        console.log(result);

        // 每次调用iterator上的next方法，可以执行一个yield状态
        result.next()
        result.next()
        result.next()
        result.next()
        result.next()

    </script>
</body>

</html>